package com.awesome.uidemo.materialdesign.snackbar;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.awesome.common.util.ToastUtils;
import com.awesome.uidemo.R;
import com.google.android.material.snackbar.Snackbar;

public class SnackbarActivity extends AppCompatActivity {

    private LinearLayout mLinearLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_snackbar);
        mLinearLayout = findViewById(R.id.ll_container);
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showSnackbar();
            }
        });
    }

    @SuppressLint("ShowToast")
    private void showSnackbar() {
        Snackbar.make(mLinearLayout,"标题",Snackbar.LENGTH_LONG)
                .setAction("点击事件", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ToastUtils.showToast(SnackbarActivity.this,"Toast");
                    }
                })
                .setDuration(Snackbar.LENGTH_LONG)
                .show();
    }
}